<template>
  <el-card class="box-card">
  	<div slot="header" class="clearfix">
      <span>保养提醒 </span>
      <el-button style="float: right; padding: 3px 0" type="text" ></el-button>
  	</div>
  <div>
    <el-table v-loading="loading" :data="takecareList">
      <el-table-column label="状态" align="center" >
         <template slot-scope="scope">
           <i class="el-icon-message-solid" style="font-size: 30px;color: rgb(235, 98, 59);" @click="handleRead(scope.row)"></i>
         </template>
      </el-table-column>
      <el-table-column label="单位名称" align="center" prop="zyxDevice.unitname" />
       <el-table-column label="设备类别" align="center" prop="zyxDevice.devicetype" />
      <el-table-column label="设备型号" align="center" prop="zyxDevice.devicemodel" />
      <el-table-column label="保养周期" align="center" prop="zyxTakecare.warncycle" />
      <el-table-column label="上次保养时间" align="center" prop="lastdate" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zyxTakecare.lastdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下次保养时间" align="center" prop="nexttakecaredate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zyxTakecare.nexttakecaredate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="距离时间" align="center" prop="zyxTakecare.distanceday" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
   </el-card>
</template>

<script>
import { listMyTakecare, getTakecare, delTakecare, addTakecare, updateTakecare, exportTakecare } from "@/api/zyx/takecare";
import { listWarn,updMyWarnRead} from "@/api/zyx/warn";
export default {
  name: "Takecare",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 保养信息表格数据
      takecareList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否投保字典
      isinsureOptions: [],
      devicetypeOptions:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 6,
        deviceid: null,
        devicemodel:null,
        warntype:null,
        orderByColumn:'create_time',
        isAsc:'desc',
        isread:'N',
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        startdate: [
          { required: true, message: "起始日期不能为空", trigger: "blur" }
        ],
        warncycle: [
          { required: true, message: "提醒周期不能为空", trigger: "blur" },
          {
            pattern: /^[1-9][0-9]*$/,
            message: "请输入正确的提醒天数",
            trigger: "blur"
          }
        ],
        warndaynum: [
          { required: true, message: "提前多少天提醒不能为空", trigger: "blur" },
          {
            pattern: /^[1-9][0-9]*$/,
            message: "请输入正确的提醒天数",
            trigger: "blur"
          }
        ],

      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_yes_no").then(response => {
      this.isinsureOptions = response.data;
    });
    this.getDicts("zyx_devicetype").then(response => {
      this.devicetypeOptions = response.data;
    });
  },
  methods: {
  handleRead(row){
        updMyWarnRead(row.id).then(response => {
          this.getList();
        });
      },
    // 设备类别字典字典翻译
    devicetypeFormat(row, column) {
      return this.selectDictLabel(this.devicetypeOptions, row.zyxDevice.devicetype);
    },
    // 是否投保字典翻译
    isinsureFormat(row, column) {
      return this.selectDictLabel(this.isinsureOptions, row.zyxDevice.isinsure);
    },
    /** 查询保养信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.warntype="1";
      listWarn(this.queryParams).then(response => {
        this.takecareList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        departid: null,
        deviceid: null,
        startdate: null,
        nextdate: null,
        warncycle: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null,
        warndaynum:null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

  }
};
</script>
